﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WinfromTest001
{
    class DbHelper
    {
        private readonly static string conString = "server=DESKTOP-RQLSIQ5\\SQLEXPRESS;" +
            "database=Admin10;uid=sa;pwd=20010719;";
        public static DataTable GetDataTable(string sql)
        {
            SqlConnection sqlConnection = new SqlConnection(conString);       
            SqlDataAdapter dataAdapter = new SqlDataAdapter(sql, sqlConnection);
            DataTable dt = new DataTable();
            sqlConnection.Open();
            dataAdapter.Fill(dt);
            return dt;
        }


        /// <summary>
        /// 添加或修改的方法
        /// </summary>
        /// <param name="sql"></param>
        /// <returns></returns>
        public static int AddOrEditDeleteSave(string sql)
        {
            SqlConnection sqlConnection = new SqlConnection(conString);

            SqlCommand command = new SqlCommand(sql, sqlConnection);
            sqlConnection.Open();
            return command.ExecuteNonQuery();
        }
    }
}
